class Action_Bit
  attr_accessor :id
  attr_accessor :actor
  # 0=中断点（多级行动时，可以在此行动后面插入行动）
  # 1=对actor施加动画(int)
  # 2=对actor施加伤害(Damge_Info)
  # 3=对actor施加回血
  # 4=对actor添加浮动文本
  attr_accessor :type
  attr_accessor :detail
  attr_accessor :duration_time
  attr_accessor :delay_time
  attr_accessor :left_duration_time
  attr_accessor :left_delay_time # 指定id流完成才会开始执行这个
  attr_accessor :is_triggered
  attr_accessor :sprite
  attr_accessor :is_block #为true时当前行动完成才会执行后续行动
  def initialize(actor, type)
    @id = 0
    @actor = actor
    @type = type
    @detail = nil
    @is_triggered = false
    @is_block = false
    self.set_duration_time(0)
    self.set_delay_time(0)
  end
  def set_detail(value)
    @detail = value
    if @type == 1
      if @detail > 0
        animation = $data_animations[@detail]
        set_duration_time(animation.frame_max)
      else
        set_duration_time(8)
      end
    end
    return self
  end
  def set_duration_time(value)
    @duration_time = value
    @left_duration_time = value
    return self
  end
  def set_delay_time(value)
    @delay_time = value
    @left_delay_time = value
    return self
  end
  def set_block
    @is_block = true
    return self
  end
  def is_completed?
    return (@is_triggered and @left_duration_time == 0)
  end
  def update
    if @left_delay_time > 0
      @left_delay_time -= 1
      return
    end
    if @is_triggered == false
      case @type
      when 0
        # do nothing
      when 1
        handle_animation
      when 2
        handle_damge
      when 3
        handle_hp_recovery
      when 4
        handle_popup_text
      end
      @is_triggered = true
    end
    if @left_duration_time > 0
      @left_duration_time -= 1
    end
  end
  def handle_animation
    if @detail != nil && @detail > 0
      @actor.animation_id = @detail
    else
      @actor.white_flash = true
    end
  end
  def handle_damge
    @actor.animation_id = @detail.hit_animation_id
    @actor.add_damge(@detail)
  end
  def handle_hp_recovery
    @actor.recover_hp(@detail)
  end
  def handle_popup_text
    @actor.add_popup_text(@detail, 1)
  end
end
